package com.mlyol.ocp;

public class Demo1 {

    public static void main(String[] args) {
        new Demo1().run();
    }

    void run(){
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Rectangle());
        graphicEditor.drawShape(new Triangle());
    }

    class GraphicEditor {
        public void drawShape(Shape s) {
            if (s.m_type == 1) {
                this.drawRectangle(s);
            } else if (s.m_type == 2) {
                this.drawCircle(s);
            }
            // edit:2
            else if (s.m_type == 3) {
                this.drawTriangle(s);
            }
        }
        public void drawRectangle(Shape shape) {
            System.out.println("矩形");
        }
        public void drawCircle(Shape shape) {
            System.out.println("圆形");
        }
        // edit:3
        public void drawTriangle(Shape shape) {
            System.out.println("三角形");
        }

    }
    class Shape {
        int m_type;
    }
    class Rectangle extends Shape {
        Rectangle() {
            this.m_type = 1;
        }
    }
    class Circle extends Shape {
        Circle() {
            this.m_type = 2;
        }
    }
    // edit:1
    class Triangle extends Shape {
        Triangle() {
            this.m_type=3;
        }
    }


}
